package per.hx.bs.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import per.hx.bs.constant.Setting;
import per.hx.bs.config.WxProperties;

/**
 * @author HuXing
 * @date 2018/5/10  22:01
 */
@Configuration
@EnableConfigurationProperties(WxProperties.class)
public class WxUtil {

    private final WxProperties wxProperties;

    @Autowired
    public WxUtil(WxProperties wxProperties) {
        this.wxProperties = wxProperties;
    }

    /**
     * 上设置url
     *
     * @param code code
     * @return url
     */
    public String setURL(String code) {
        StringBuilder url = new StringBuilder(Setting.WEIXING_URL);
        url.append("?appid=").append(wxProperties.getAppid())
                .append("&secret=").append(wxProperties.getSecret())
                .append("&js_code=").append(code)
                .append("&grant_type=").append(wxProperties.getGrantType());

        return url.toString();
    }
}
